package com.mashibing.servicemap.remote;

import com.mashibing.internalcommon.constant.AmapConfigConstants;
import com.mashibing.internalcommon.dto.ResponseResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.http.ResponseEntity;
import org.springframework.stereotype.Service;
import org.springframework.web.client.RestTemplate;

/**
 * @title: MapDistrictClient
 * @Author Z先森
 * @Date: 2022/9/27 10:50
 * @Version 1.0
 */
@Service
public class MapDistrictClient {

    @Value("${amap.key}")
    private String key;
    @Autowired
    private RestTemplate restTemplate;

    public String initDicDistrict(String keywords) {
        //1.拼装请求的URL
        StringBuilder urlBuild = new StringBuilder();
        urlBuild.append(AmapConfigConstants.DISTRICT_URL);
        urlBuild.append("?");
        urlBuild.append("keywords=");
        urlBuild.append(keywords);
        urlBuild.append("&");
        urlBuild.append("subdistrict=");
        urlBuild.append("3");
        urlBuild.append("&");
        urlBuild.append("key=");
        urlBuild.append(key);
        ResponseEntity<String> entity = restTemplate.getForEntity(urlBuild.toString(), String.class);
        String body = entity.getBody();

        return body;
    }
}
